<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta content="phalconplus API doc" name="description">
    <title>
                    phalconplus API Documentation
            </title>
    <link rel="stylesheet" type="text/css" href="../../../../asset/static/prettify.css" />

<script src="../../../../asset/static/prettify.js"></script>
<script src="../../../../asset/api_definition.js"></script>


                        <link rel="stylesheet" type="text/css" href="../../../../asset/static/prettify.css" />
                    <link rel="stylesheet" type="text/css" href="../../../../asset/static/zephir-theme.css" />
            
    

                        <script src="../../../../asset/static/prettify.js"></script>
                                    <script src="../../../../asset/api_definition.js"></script>
                    <script src="../../../../asset/static/jquery.min.js"></script>
                    <script src="../../../../asset/static/zephir-doc.js"></script>
                <script type="application/javascript">let ZepCurrentPath = '../../../../'</script>
    </head>
 <body onload="prettyPrint()">
        <div id="top-bar">
            <div id="top-left">
                                    phalconplus Documentation <span class="version">v1.3.0-development</span>
                            </div>
            <div id="top-right">
            </div>
        </div>
        <div id="body">
            <div id="body-left">
                <div class="header-search">
                    <input class="search-box" placeholder="Search for a class or namespace " type="text" />
                    <div id="menu-wrapper">
                    </div>
                </div>
            </div>
            <div id="body-right">
                <div class="content">
                    
<div class="breadcrumb">
    
    <ul>
        
        <li><a href="../../../../index.html">Home</a></li>
        
                <li><a href="../../../../classes.html">Classes</a></li>
                <li><a href="../../../../class/PhalconPlus/App/Module/AbstractModule.html">PhalconPlus\App\Module\AbstractModule</a></li>
                <li><a >Source</a></li>
                
    </ul>
    
</div>
<div class="class-header source clearfix">
    
    <div class="access-buttons">
        <a class="zep-button" href="../../../../class/PhalconPlus/App/Module/AbstractModule.html">Class</a>

            </div>
    
    <div class="class-full-name">
        <span class="class-type">Class</span>
        
                <span class="namespace-piece">
            <a href="../../../../namespace/PhalconPlus.html">PhalconPlus</a>
        </span>
                <span class="namespace-piece">
            <a href="../../../../namespace/PhalconPlus/App.html">App</a>
        </span>
                <span class="namespace-piece">
            <a href="../../../../namespace/PhalconPlus/App/Module.html">Module</a>
        </span>
        
        <h1 class="class-name">AbstractModule</h1>
    </div>
    
</div>

<pre class="zephir-source-file prettyprint linenums">
    namespace PhalconPlus\App\Module;
use PhalconPlus\App\Module\ModuleDef;
use PhalconPlus\App\App as SuperApp;
use PhalconPlus\App\Engine\AppEngine;
use Phalcon\Di\Injectable;
use PhalconPlus\Base\Exception as BaseException;
use PhalconPlus\Enum\RunMode;

abstract class AbstractModule extends Injectable
{
    // <SuperApp>
    protected app = null { get };
    // <ModuleDef>
    protected def = null { get };
    // <AppEngine>
    protected engine = null { get };

    public function __construct(<SuperApp> app, <ModuleDef> def = null)
    {
        let this->app = app; // Hold SuperApp instance
        let this->def = def; // Module should have it's definition.
        let this->_dependencyInjector = app->di();
    }

    public function isPrimary()
    {
        return this->def->getIsPrimary() === true; // Report is primary or not
    }

    public function isCli()
    {
        return this->def->getRunMode()->isCli();
    }

    public function isWeb()
    {
        return this->def->getRunMode()->isWeb();
    }

    public function isSrv()
    {
        return this->def->getRunMode()->isSrv();
    }

    public function isMicro()
    {
        return this->def->getRunMode()->isMicro();
    }

    public function getName()
    {
        return this->def->getName();
    }

    public function app() -> <SuperApp>
    {
        return this->app;
    }

    public function di() -> <\Phalcon\Di>
    {
        return this->_dependencyInjector;
    }

    public function def() -> <ModuleDef>
    {
        return this->def;
    }

    public function config() -> <\Phalcon\Config>
    {
        return this->def->config();
    }

    public function engine() -> <AppEngine>
    {
        return this->engine;
    }

    public function __call(string method, array params = [])
    {
        return call_user_func_array(
            [this->def, method],
            params
        );
    }

    public function exec(array params = [])
    {
        if !this->def->isPrimary() {
            throw new BaseException("Only primary module can be executed");
        }

        var eventsManager,
            engineClass,  
            engineName = this->def->getMapClassName();
        
        let eventsManager = <ManagerInterface> this->_eventsManager;
        if typeof eventsManager == "object" {
            if eventsManager->fire("module:beforeStartEngine", this, [engineClass, params]) === false {
                // 
            }
        }

        if empty this->engine {
            this->registerEngine();
        }
        this->di()->setShared("appEngine", this->engine);

        return call_user_func_array(
            [this->engine, "exec"], 
            params
        );
    }

    abstract public function registerAutoloaders();
    abstract public function registerServices();
    public function registerEvents()
    {
        // 
    }

    public function registerEngine() -> <AbstractModule>
    {
        if !this->def->isPrimary() {
            return this;
        }
        
        var engineClass,  
            engineName = this->def->getMapClassName();
        let engineClass = "\\PhalconPlus\\App\\Engine\\".engineName;

        let this->engine = new {engineClass}(this);

        return this;
    }
}
</pre>
                </div>
            </div>
        </div>
    </body>
</html>
